﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.Module.Default.model;
using Jxym.DBUtility;
using System.Data.SqlClient;
using System.Reflection;


namespace Jxym.wlkc2011.Module.Default.server.Files
{
    public partial class FoldersAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int modelid = 0;
                
                MsSqlDal<Folders> iD = new MsSqlDal<Folders>();
                MsSqlDal<model.Folders> inotice = new MsSqlDal<model.Folders>();
                string text = ""; if (Request.Params["text"] != null) { text = Request.Params["text"]; }
                int parentNodeId = 0; if (Request.Params["parentnode"] != null) { parentNodeId = Convert.ToInt32(Request.Params["parentnode"]); }
                int nodeId = 0; if (Request.Params["nodeId"] != null) { nodeId = Convert.ToInt32(Request.Params["nodeId"]); }
                if (Request.Params["modelid"] != null) modelid = Convert.ToInt32(Request.Params["modelid"]);
                string returnStr = "{'success':false,'msg':'参数错误'}";
                if (text != "")
                {
                    if (nodeId != 0)
                    {
                        model.Folders fo = inotice.GetModel("ID=" + nodeId, null);
                        if (MyGet.GetPermissionsValidation(modelid,"U", Jxym.Common.Request.AdminID("user")) && Jxym.Common.Request.AdminID("user").Equals(fo.CreateID.ToString()))
                        {
                            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", nodeId), new SqlParameter("@Name", text) };
                            iD.Updata(parameters);
                            returnStr = "{'success':true,'msg':'编辑完成'}";
                        }
                        else
                        {
                            returnStr = "{'success':false,'msg':'对不起，您没有编辑权限'}";
                        }
                    }
                    else
                    {
                        if (MyGet.GetPermissionsValidation(modelid,"A", Jxym.Common.Request.AdminID("user")))
                        {
                            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Name", text), new SqlParameter("@ParentID", parentNodeId), new SqlParameter("@CreateID", Jxym.Common.Request.AdminID("user")) };
                            iD.Add(parameters);
                            returnStr = "{'success':true,'msg':'添加完成'}";
                        }
                        else
                        {
                            returnStr = "{'success':false,'msg':'对不起，您没有添加权限'}";
                        }
                    }
                }
                else
                {
                    returnStr = "{'success':false,'msg':'添加失败'}";
                }
                Response.Write(returnStr);
            }
        }
    }
}